package listener;

import javax.servlet.*;

public class ApplicationListener implements ServletContextListener, ServletContextAttributeListener {
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        System.out.println("context-initialized");
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        System.out.println("context-destroyed");
    }

    @Override
    public void attributeAdded(ServletContextAttributeEvent scae) {
        System.out.println("attribute-added-ServletContext: "+scae.getName()+" "+scae.getValue());
    }

    @Override
    public void attributeRemoved(ServletContextAttributeEvent scae) {
        System.out.println("attributeRemoved-ServletContext: "+scae.getName()+" "+scae.getValue());
    }

    @Override
    public void attributeReplaced(ServletContextAttributeEvent scae) {
        // 旧值 新值  key相同
        // 新值
        ServletContext servletContext = scae.getServletContext();
        System.out.println("attributeReplaced-ServletContext: "+scae.getName()+" "+scae.getValue()+" newValue:"+servletContext.getAttribute(scae.getName()));
    }
}
